home *** CD-ROM | disk | FTP | other *** search
- ******* ibox.lib/SelectNode *************************************************
- *
- * NAME
- * SelectNode -- select the Nth node from an Exec List
- *
- * SYNOPSIS
- * node = SelectNode( list, index )
- * D0 a0 d1
- *
- * struct Node * __asm SelectNode( register __a0 struct List *,
- * register __d1 WORD );
- *
- * FUNCTION
- * Selects a node in an Exec list by numerical position in the list.
- *
- * INPUTS
- * list - pointer to List or MinList
- * index - the number of the element to select.
- *
- * RESULT
- * node - the address of the node, or NULL if the index is
- * larger than the last node in the list.
- *
- * EXAMPLE
- *
- * NOTES
- *
- * BUGS
- *
- * SEE ALSO
- * exec/lists.h, exec/nodes.h
- *
- *****************************************************************************
- * Written by Joe Pearce. Modified for SAS/DICE by Talin
- *
- include 'exec/lists.i'
-
- SECTION text,CODE
-
- xdef _SelectNode,@SelectNode
-
- _SelectNode:
- move.l 4(sp),a0 ; get list
- move.l 8(sp),d1 ; get index
- @SelectNode:
- moveq #0,d0 ; prime for error return
-
- ; note since list heads are also nodes, we can just use the LN_SUCC field.
-
- loop: move.l LN_SUCC(a0),a0 ; go to first/next node
- tst.l LN_SUCC(a0) ; is this really the header?
- beq.s no_node ; yep, so return NULL
-
- dbra d1,loop ; loop till we drop
-
- move.l a0,d0 ; found a valid node at index
- no_node: rts
-
- end
-